package com.mis.clothespos.in.controller;

import com.mis.clothespos.clothes.domain.clothes;
import com.mis.clothespos.clothes.service.IclothesService;
import com.mis.clothespos.common.AjaxResult;
import com.mis.clothespos.common.BaseController;
import com.mis.clothespos.in.domain.In;
import com.mis.clothespos.in.service.inService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/in")
public class inController extends BaseController {

    @Autowired
    inService in_Service;
    @Autowired
    IclothesService iclothesService;


    /**
    * @Description:  添加已有衣服的库存
    * @Param:  In类
    * @return:  AjaxResult
    * @Author: 黄海滨
    * @Date:
    */
    @PostMapping("/addOld")
    @ResponseBody
    public AjaxResult addOld(In old){
        Integer ifold=in_Service.checkIfOld(old);
        if(ifold==0){
            return error("此商品不存在");
        }
        old.setId(in_Service.selectByDetail(old));
        in_Service.insert(old);
        return toAjax(in_Service.updateNumber(old));
    }


    /**
    * @Description: 添加新衣服的库存
    * @Param:  In
    * @return:  AjaxResult
    * @Author: 黄海滨
    * @Date:
    */
    @PostMapping("/addNew")
    @ResponseBody
    public AjaxResult addNew(In newClothes){
        Integer ifold=in_Service.checkIfOld(newClothes);
        if(ifold==0){
            return error("此商品已存在");
        }
        clothes clothes=new clothes();
        clothes.setClothestype(newClothes.getClothestype());
        clothes.setColortype(newClothes.getColor());
        clothes.setStylename(newClothes.getStyletype());
        clothes.setPrice(Long.valueOf(newClothes.getPrice()));
        clothes.setDel(0);
        clothes.setName(newClothes.getName());
        clothes.setNumber(newClothes.getNumber());
        clothes.setSizetype(newClothes.getSize());
        iclothesService.insert(clothes);
        return toAjax(in_Service.insert(newClothes));



    }

}
